package com.slink.fxfk.demo.domain.po;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
 * 与tag组成单边多对多：post->tag
 * @author 新
 *
 */
@Entity
@Table(name="t_post")
public class Post {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private String id;
	
	@ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
	/**
	 * @JoinTable指定中间表的配置，name指定表名，joinColumns指定该表（post对应的表）与中间表的对应关系，
	 * inverseJoinColumns指定另一端（也就是tag对应的表）与中间表的对应关系
	 * @JoinTable配置都是针对中间表的配置，因此post_id、tag_id都指中间表的列，
	 * referencedColumnName 为实体类的关联列，默认为主键，若为主键则referencedColumnName可省略
	 */
	@JoinTable(
			name="tb_tag_post",
			joinColumns=@JoinColumn(name="post_id",referencedColumnName="id"),
			inverseJoinColumns=@JoinColumn(name="tag_id",referencedColumnName="id")
			)
	private Set<Tag> tags = new HashSet<Tag>();
	
	private String title;
	
	@Column(columnDefinition="text")
	private String content;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Set<Tag> getTags() {
		return tags;
	}

	public void setTags(Set<Tag> tags) {
		this.tags = tags;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	
}
